#include <stdio.h>
#include <stdlib.h>

typedef struct BTNode
{
    int data;
    struct BTNode* lchild;
    struct BTNode* rchild;
}BTNode;

BTNode* IniNode(int data);
BTNode* CreateTree(int *preOrder, int size, int *pused);
void inOrder(BTNode* bst);
void shuru(int cc, int *array)
{
    int i = 0;
    int ch = cc;
    while(ch != '\n')
    {
        // 持续输入字符串并存储
		// printf("%d", ch);
        array[i]==ch;
        i++;
        scanf("%d", &ch);
    }
}

int main()
{
    int *preOrder;
    int *preAdr[100];
    int i = 0;
    int count = 0;
    int *array;
    array=(int*)calloc(100,sizeof(int));
    // 利用数组存储地址头文件，这样第一步就可以判断了
    int cc;
    while(scanf("%d", &cc) != EOF)
    {
		// printf("%d", cc);
        shuru(cc, array);
		// printf("%d", *array);
        preAdr[count] = array;
        count++;
    }
    // 处理后依次输出
    int pused = 0;
    for(; i < count; i++)
    {
        int size = sizeof(preAdr[i])/sizeof(int);
        BTNode *root = CreateTree(preAdr[i], size, &pused);
        inOrder(root);
    }
    return 0;
}

BTNode* IniNode(int data)
{
    BTNode *pTmp = (BTNode*)malloc(sizeof(BTNode));
    if(NULL == pTmp)
    {
        exit(0);
    }
    pTmp->data = data;
    pTmp->lchild = NULL;
    pTmp->rchild = NULL;
    return pTmp;
}

BTNode* CreateTree(int preOrder[], int size, int *pused)
{
    if(size == 0)
    {
        *pused = 0;
        return NULL;
    }
    int lchildused = 0;
    int rchildused = 0;
    int rootValue = preOrder[0];

    if(rootValue == -1)
    {
        *pused = 1;
        return NULL;
    }
    BTNode *root = IniNode(rootValue);
    root->lchild = CreateTree(preOrder + 1, size - 1, &lchildused);
    root->rchild = CreateTree(preOrder + 1 + lchildused, size - 1 - lchildused, &rchildused);
    *pused = 1 + lchildused + rchildused;
    return root;
}

void inOrder(BTNode* bst)
{
    if(NULL != bst)
    {
        inOrder(bst->lchild);
        printf("%d ", bst->data);
        inOrder(bst->rchild);
    }
}
